<?php

namespace App\Http\Controllers;

use App\Models\Collect;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Requests\CollectRequest;

class CollectsController extends Controller
{
    public function __construct()
    {
        $this->middleware('auth', ['except' => ['index', 'show']]);
    }

	public function index()
	{
		$collects = Collect::paginate();
		return view('collects.index', compact('collects'));
	}

    public function show(Collect $collect)
    {
        return view('collects.show', compact('collect'));
    }

	public function create(Collect $collect)
	{
		return view('collects.create_and_edit', compact('collect'));
	}

	public function store(CollectRequest $request)
	{
		$collect = Collect::create($request->all());
		return redirect()->route('collects.show', $collect->id)->with('message', 'Created successfully.');
	}

	public function edit(Collect $collect)
	{
        $this->authorize('update', $collect);
		return view('collects.create_and_edit', compact('collect'));
	}

	public function update(CollectRequest $request, Collect $collect)
	{
		$this->authorize('update', $collect);
		$collect->update($request->all());

		return redirect()->route('collects.show', $collect->id)->with('message', 'Updated successfully.');
	}

	public function destroy(Collect $collect)
	{
		$this->authorize('destroy', $collect);
		$collect->delete();

		return redirect()->route('collects.index')->with('message', 'Deleted successfully.');
	}
}